import axios from "axios";

const request = axios.create({
    // 后端接口地址和调用的路径进行拼接
    // 本地开发地址
    baseURL: 'http://localhost:8900/',
    //访问超时时间是5秒s
    timeout: 5000,
    withCredentials: true,
    AccessControlAllowCredentials: true
});

/**
 * 封装get方法
 */
export function get(url, params = {}) {
    return new Promise((resolve, reject) => {
        request
            .get(url, {
                params: params
            })
            .then(response => {
                resolve(response.data);
            })
            .catch(err => {
                reject(err);
            });
    });
}

/**
 * 封装post方法
 */
export function post(url, data = {}) {
    return new Promise((resolve, reject) => {
        request
            .post(url, data)
            .then(response => {
                resolve(response.data);
            })
            .catch(err => {
                reject(err);
            });
    });
}

export default request;
